package com.googlecode.continuity.core.web.controller.rpc;

import org.acegisecurity.context.SecurityContextHolder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.googlecode.continuity.core.security.SecurityUserToken;
import com.googlecode.continuity.core.service.UserService;
import com.googlecode.continuity.core.web.gwt.ContinuityUser;
import com.googlecode.continuity.core.web.gwt.UserRpc;

/**
 * UserRpcImpl
 *
 * @author Peter Schmitt <aragos@aragos.de>
 */
public class UserRpcImpl implements UserRpc {
  private UserService userService;

  protected final Log logger = LogFactory.getLog(getClass());

  public UserService getUserService() {
    return userService;
  }

  public void setUserService(UserService userService) {
    this.userService = userService;
  }

  public int getUserCount() {
    logger.info("returning user count from rpc");
    return userService.getUserCount();
  }

  public ContinuityUser getCurrentUser() {
    return ((SecurityUserToken) SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getUser();
  }
}
